<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="500px"
    @close="close"
  >
    <el-form
      ref="formRef"
      label-width="80px"
      :model="invoiceDetail"
      :rules="rules"
    >
      <el-form-item label="发票类型">
        {{ invoiceDetail.type_alias }}
      </el-form-item>
      <el-form-item label="抬头">{{ invoiceDetail.header }}</el-form-item>
      <el-form-item label="税号">{{ invoiceDetail.tax_no }}</el-form-item>
      <el-form-item label="邮箱">{{ invoiceDetail.email }}</el-form-item>
      <el-form-item label="注册地址">
        {{ invoiceDetail.register_address }}
      </el-form-item>
      <el-form-item label="注册电话">
        {{ invoiceDetail.register_mobile }}
      </el-form-item>
      <el-form-item label="开户行">
        {{ invoiceDetail.bank_name }}
      </el-form-item>
      <el-form-item label="开户账号">
        {{ invoiceDetail.bank_account }}
      </el-form-item>
      <el-form-item label="邮寄地址">
        {{ invoiceDetail.address }}
      </el-form-item>
      <el-form-item label="收件人">
        {{ invoiceDetail.receive }}
      </el-form-item>
      <el-form-item label="收件电话">
        {{ invoiceDetail.receive_mobile }}
      </el-form-item>
      <el-form-item label="开票状态">
        {{ invoiceDetail.status_alias }}
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="close">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { defineComponent, reactive, toRefs } from 'vue'
  import { getDetail } from '@/api/ordeInvoice'
  import { baseURL } from '@/config'

  export default defineComponent({
    name: 'InvoiceDetail',
    emits: ['fetch-data'],
    // 处于生命周期函数 beforeCreate 和 Created 两个钩子函数之前的函数
    // 执行 setup 时，组件实例尚未被创建（在 setup() 内部，this 不会是该活跃实例的引用，即不指向vue实例，Vue 为了避免我们错误的使用，直接将 setup函数中的this修改成了 undefined）
    setup() {
      console.log(window.location.host)
      const state = reactive({
        formRef: null,
        mettingList: [],
        uploadActionUrl: baseURL + 'upload/ajaxUploads',
        form: {
          id: '',
          name: '',
          mobile: '',
          weixin: '',
          email: '',
          company: '',
          position: '',
        },
        invoiceDetail: [],
        rules: {
          metting_id: [
            { required: true, trigger: 'blur', message: '请选择所属会议' },
          ],
          name: [
            { required: true, trigger: 'blur', message: '请输入嘉宾名称' },
          ],
          mobile: [
            { required: true, trigger: 'blur', message: '请输入手机号' },
            { pattern: /^1\d{10}$/, message: '请输入正确手机号' },
          ],
          company: [
            { required: true, trigger: 'blur', message: '请输入公司名称' },
          ],
          position: [
            { required: true, trigger: 'blur', message: '请输入职位' },
          ],
          email: [
            {
              type: 'email',
              trigger: 'change',
              message: '请输入正确的邮箱地址',
            },
          ],
        },
        title: '',
        dialogFormVisible: false,
        roleList: [],
      })
      const showEdit = (row) => {
        state.title = '发票信息'
        state.form = Object.assign({}, row)
        detail()
      }
      const close = () => {
        state['formRef'].resetFields()
        state.dialogFormVisible = false
      }
      const detail = async () => {
        const { data } = await getDetail({ id: state.form.invoice_id })
        if (data) {
          state.invoiceDetail = data
          state.dialogFormVisible = true
        }
      }
      const handleSuccess = (response) => {
        if (response.code == 0) {
          state.form.logo = response.data[0].path
        }
      }
      const dateChange = (val) => {
        console.log(val)
      }

      // 与模板一起使用：需要返回一个对象 (在setup函数中定义的变量和方法最后都是需要 return 出去的 不然无法再模板中使用)
      return {
        ...toRefs(state),
        showEdit,
        close,
        detail,
        handleSuccess,
        dateChange,
      }
    },
  })
</script>
<style lang="scss" scoped>
  .tip {
    margin: 0px;
    color: red;
  }
  :deep() {
    .el-upload-list {
      display: none;
    }
  }
</style>
